// ignore_for_file: dangling_library_doc_comments, slash_for_doc_comments
import 'dart:convert';

import 'package:flutter/widgets.dart';
import 'package:json_annotation/json_annotation.dart';

import '../../../common_code/models/base_model.dart';

part 'short_video_list_model.g.dart';

/*** 
 * @Author: Zhong
 * @Date: 2025-08-26 10:54:30
 * @LastEditors: Zhong zhongxiaodong@eenet.com
 * @LastEditTime: 2025-08-26 11:16:45
 * @FilePath: /wan_android_flutter/lib/module_code/short_video/models/short_video_list_model.dart
 * @Description: 
 */

@JsonSerializable(explicitToJson: true)
class ShortVideoListModel extends BaseModel {
  ShortVideoListDataModel? data;

  // 构造函数
  ShortVideoListModel({
    this.data,
    super.errorCode,
    super.errorMsg,
    super.msg,
    super.status,
  });

  factory ShortVideoListModel.fromJson(Map<String, dynamic> json) =>
      _$ShortVideoListModelFromJson(json);

  Map<String, dynamic> toJson() => _$ShortVideoListModelToJson(this);
}

@JsonSerializable(explicitToJson: true)
class ShortVideoListDataModel {
  ShortVideoListResponseModel? response;

  ShortVideoListDataModel({this.response});

  factory ShortVideoListDataModel.fromJson(Map<String, dynamic> json) =>
      _$ShortVideoListDataModelFromJson(json);

  Map<String, dynamic> toJson() => _$ShortVideoListDataModelToJson(this);
}

@JsonSerializable(explicitToJson: true)
class ShortVideoListResponseModel {
  List<ShortVideoListItemModel>? videos;

  ShortVideoListResponseModel({this.videos});

  factory ShortVideoListResponseModel.fromJson(Map<String, dynamic> json) =>
      _$ShortVideoListResponseModelFromJson(json);

  Map<String, dynamic> toJson() => _$ShortVideoListResponseModelToJson(this);
}

@JsonSerializable(explicitToJson: true)
class ShortVideoListItemModel {
  String? id;
  String? title;
  String? poster;
  String? poster_small;
  String? poster_big;
  String? poster_pc;
  String? source_name;
  String? play_url;
  String? duration;
  String? url;

  String? publish_time;
  String? new_cate_v2;
  String? previewUrlHttp;
  String? author_avatar;

  int? like;

  @SizeConverter()
  Size? imageRawSize;

  ShortVideoListItemModel({
    this.id,
    this.title,
    this.poster,
    this.poster_small,
    this.poster_big,
    this.poster_pc,
    this.source_name,
    this.play_url,
    this.duration,
    this.url,
    this.publish_time,
    this.new_cate_v2,
    this.previewUrlHttp,
    this.author_avatar,
    this.like,
    this.imageRawSize,
  });

  factory ShortVideoListItemModel.fromJson(Map<String, dynamic> json) =>
      _$ShortVideoListItemModelFromJson(json);

  Map<String, dynamic> toJson() => _$ShortVideoListItemModelToJson(this);
}

// Size 转换器
class SizeConverter implements JsonConverter<Size, Map<String, dynamic>> {
  const SizeConverter();

  @override
  Size fromJson(Map<String, dynamic> json) {
    return Size(
      (json['width'] as num).toDouble(),
      (json['height'] as num).toDouble(),
    );
  }

  @override
  Map<String, dynamic> toJson(Size size) {
    return {'width': size.width, 'height': size.height};
  }
}
